package com.dingwei.superiordiary.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.mvp.presenter.BindPhonePresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.AppManager;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created time 2018/3/8.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class BindPhoneActivity extends BaseActivity implements Contract.BindPhoneView {

    BindPhonePresenter bindPhonePresenter = new BindPhonePresenter(this);
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.tv_type)
    TextView tvType;
    @Bind(R.id.et_phone)
    EditText etPhone;
    @Bind(R.id.tv_getcode)
    TextView tvGetcode;
    @Bind(R.id.et_code)
    EditText etCode;
    @Bind(R.id.et_password)
    EditText etPassword;
    @Bind(R.id.btn_regsiter)
    Button btnRegsiter;
    @Bind(R.id.et_super_password)
    EditText etSuperPassword;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_bind_phone;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        tvTitle.setText("绑定手机号");


        switch (getIntent().getStringExtra("fromtype")) {
            case "2":
                tvType.setText("QQ:" + getIntent().getStringExtra("frominfo") + "已授权登录，绑定手机号码");
                break;
            case "1":
                tvType.setText("微信:" + getIntent().getStringExtra("frominfo") + "已授权登录，绑定手机号码");
                break;
            case "wb":
                tvType.setText("微博:" + getIntent().getStringExtra("frominfo") + "已授权登录，绑定手机号码");
                break;
        }
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.tv_getcode, R.id.btn_regsiter})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.tv_getcode:
                bindPhonePresenter.getCode(etPhone.getText().toString());
                break;
            case R.id.btn_regsiter:
                bindPhonePresenter.bindPhone(etPhone.getText().toString(), getIntent().getStringExtra("fromtype"), etCode.getText().toString(), getIntent().getStringExtra("fromuuid"), getIntent().getStringExtra("frominfo"),etPassword.getText().toString(),etSuperPassword.getText().toString());
                break;
        }
    }

    @Override
    public void CountDownTimerFinish() {
        tvGetcode.setTextColor(getResources().getColor(R.color.theme_color));
        tvGetcode.setText("获取验证码");
        tvGetcode.setEnabled(true);
    }

    @Override
    public void CountDownTimeronTick(long millisUntilFinished) {
        tvGetcode.setTextColor(getResources().getColor(R.color.text_color_gray));
        tvGetcode.setText("请等待" + millisUntilFinished / 1000 + "秒");
        tvGetcode.setEnabled(false);
    }

    @Override
    public void loginSuccess() {
        finish();
        AppManager.getAppManager().finishActivity(LoginActivity.class);
    }
}
